package com.javalei.business;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Properties;


/**
 * Created by wuyanzu on 2017/4/12.
 */
public class SpringMail {

    public static void main(String[] args) {
        Connection conn = null ;

        Statement st=null;
        String message="" ;
        String path = "D:\\WEAVER\\ecology\\data/SQLServer";
        String linepara = "";
        String lastsqlname = "" ;
        String sqlstr="";
        linepara = "go" ;

       // linepara = "/" ;
        // TODO Auto-generated method stub
        String url= "jdbc:sqlserver://123.206.230.64:1433;DatabaseName=ecology" ;
        String url2= "jdbc:oracle:thin:@127.0.0.1:"+"1521"+":"+"orcl" ;
        String forname2 = "oracle.jdbc.OracleDriver" ;
        String forname = "com.microsoft.sqlserver.jdbc.SQLServerDriver" ;

        try{   Driver driver = (Driver)Class.forName(forname).newInstance();
            DriverManager.registerDriver(driver);
            Properties props = new Properties();
            props.put("user","sa");
            props.put("password","123");
            props.put("CHARSET", "ISO");
            conn=DriverManager.getConnection(url, props);
            System.out.println(conn);
/**
 st = conn.createStatement() ;
// String sqlstr = " use ecology ";
// st.executeUpdate(sqlstr) ;

 String sqlfile = "";
 String readline = "" ;


 File dir = new File(path);
 String fileList[] = dir.list();

 for(int i=0;i<fileList.length;i++){
 for(int j=i+1;j<fileList.length;j++){
 if(fileList[i].compareTo(fileList[j])>0){
 String tmpfileList=fileList[i];
 fileList[i]=fileList[j];
 fileList[j]=tmpfileList;
 }
 }
 }

 for(int i=0;i<fileList.length;i++){

 sqlfile = path + "/" + fileList[i] ;

 System.out.println(fileList[i] +" is running .... <br>") ;
 //         out.flush() ;

 System.out.println(fileList[i]+" ");
 readline = "" ;
 sqlstr = "" ;
 File fin = new File(sqlfile);

 BufferedReader is
 = new BufferedReader(new InputStreamReader(new FileInputStream(fin)));

 while ((readline = is.readLine()) != null)   {
 readline = readline.trim() ;
 if(!readline.equalsIgnoreCase(linepara)) sqlstr += " "+ readline ;
 else if( !(sqlstr.trim()).equals("") ) {
 message += sqlstr+"<br>" ;
 try{
     //System.out.println("正在执行"+sqlstr);
 st.executeUpdate(sqlstr) ;
 }catch(Exception ex){

 System.out.println(ex);
 readline = is.readLine();
 continue;
 }
 sqlstr = "" ;
 message = "" ;
 }

 }
 is.close();
 lastsqlname = fileList[i];

 System.out.println(lastsqlname+" execute success ! <br>") ;
 //         out.flush() ;
 }
**/
        }catch(Exception ex){
            System.out.println(ex);
        }




    }

}
